  <div class="grid_12 line">
    <div class="grid_2">姓</div>
    <div class="grid_9"><%= f.text_field :first_name %></div>
  </div>
  <div class="grid_12 line">
    <div class="grid_2">名</div>
    <div class="grid_9"><%= f.text_field :last_name %></div>
  </div>
  <div class="grid_12 line">
    <div class="grid_2">性别</div>
    <div class="grid_9">
      <%= f.radio_button :sex, :unknown, :class => :no %> <%= f.label :sex_unknown, t(:unknown), :class => :sex %>
      <%= f.radio_button :sex, :man, :class => :no %> <%= f.label :sex_man, t(:man), :class => :sex  %>
      <%= f.radio_button :sex, :woman, :class => :no %> <%= f.label :sex_woman, t(:woman), :class => :sex  %>
    </div>
  </div>
  <div class="grid_12 line">
    <div class="grid_2">职称</div>
    <div class="grid_9">
      <%= f.label :title, '添加职称描述', :id => :label_for_title, :class => customer.title.blank? ? '' : :hidden %>
      <%= f.text_field :title, :class => customer.title.blank? ? :hidden : '' %>
    </div>
    <script type="text/javascript" charset="utf-8">
      $('#label_for_title').click(function() {
        $(this).hide();
        $('#customer_title').show();
      });
      $('#customer_title').blur(function() {
        if($(this).val() == "" ) {
          $(this).hide();
          $('#label_for_title').show();
        }
      });
    </script>
  </div>
  <div class="grid_12 line">
    <div class="grid_2">公司/单位</div>
    <div class="grid_9">
      <%= f.label :organization, '添加所在单位名称', :id => :label_for_organization, :class => customer.title.blank? ? '' : :hidden %>
      <%= f.text_field :organization, :class => customer.title.blank? ? :hidden : '' %>
    </div>
    <script type="text/javascript" charset="utf-8">
      $('#label_for_organization').click(function() {
        $(this).hide();
        $('#customer_organization').show();
      });
      $('#customer_organization').blur(function() {
        if($(this).val() == "" ) {
          $(this).hide();
          $('#label_for_organization').show();
        }
      });
    </script>
  </div>
</div>
<div class="grid_12 alpha body">
  <div class="grid_12 line">
    <div class="grid_2">电话</div>
    <div id="phones" class="grid_9">
      <% customer.phones.each do |phone| %>
      <%= f.fields_for :phones, phone do |pf| %>
        <%= render :partial => 'phone_in_form.html', :locals => { :pf => pf, :phone => phone } %>
      <% end %>
      <% end %>
      <%= f.label :new_a_phone, '添加联系电话', :id => :new_a_phone, :class => (customer.phones.any? ? 'hidden' : '') %>
      <script>
        $('#new_a_phone').click(function(){
          $(this).hide();
          $('#new_phone').show();
          $(this).before(replace_id($('#phones .item').size(),"<%= j customer_phone_html_template(f) %>"));
        });     
      </script>
      <div id="new_phone" class='item <%= customer.phones.any? ? '' : 'hidden' %>'>
        <%= link_to_function "再添加一个","", :class => :new_item   %>
        <script>
          $('#new_phone a').click(function() {
            $(this).before(replace_id($('#phones .item').size(),"<%= j customer_phone_html_template(f) %>"));
          });
        </script>
      </div>
    </div>
  </div>
  <div class="grid_12 line">
    <div class="grid_2">电子邮箱</div>
    <div id="emails" class="grid_9">
      <% customer.emails.each do |email| %>
      <%= f.fields_for :emails, email do |pf| %>
        <%= render :partial => 'email_in_form.html', :locals => { :pf => pf, :email => email } %>
      <% end %>
      <% end %>
      <%= f.label :new_a_email, '添加电子邮箱地址', :id => :new_a_email, :class => (customer.emails.any? ? 'hidden' : '') %>
      <script>
        $('#new_a_email').click(function(){
          $(this).hide();
          $('#new_email').show();
          $(this).before(replace_id($('#emails .item').size(),"<%= j customer_email_html_template(f) %>"));
        });
      </script>
      <div id="new_email" class='item <%= customer.emails.any? ? '' : 'hidden' %>'>
        <%= link_to_function "再添加一个","", :class => :new_item   %>
        <script>
          $('#new_email a').click(function() {
            $(this).before(replace_id($('#emails .item').size(),"<%= j customer_email_html_template(f) %>"));
          });
        </script>
      </div>
    </div>
  </div>
  <div class="grid_12 line">
    <div class="grid_2">聊天工具</div>
    <div id="ims" class="grid_9">
      <% customer.ims.each do |im| %>      
      <%= f.fields_for :ims, im do |pf| %>
        <%= render :partial => 'im_in_form.html', :locals => { :pf => pf, :im => im } %>
      <% end %>
      <% end %>
      <%= f.label :new_a_im, '添加聊天工具联系方式', :id => :new_a_im, :class => (customer.ims.any? ? 'hidden' : '') %>
      <script>
        $('#new_a_im').click(function(){
          $(this).hide();
          $('#new_im').show();
          $(this).before(replace_id($('#ims .item').size(),"<%= j customer_im_html_template(f) %>"));
        });
      </script>
      <div id="new_im" class='item <%= customer.ims.any? ? '' : 'hidden' %>'>
        <%= link_to_function "再添加一个","", :class => :new_item   %>
        <script>
          $('#new_im a').click(function() {
            $(this).before(replace_id($('#ims .item').size(),"<%= j customer_im_html_template(f) %>"));
          });
        </script>
      </div>
    </div>
  </div>
  <div class="grid_12 line">
    <div class="grid_2">网站</div>
    <div id="web_sites" class="grid_9">
      <% customer.web_sites.each do |web_site| %>
      <%= f.fields_for :web_sites, web_site do |pf| %>
        <%= render :partial => 'web_site_in_form.html', :locals => { :pf => pf, :web_site => web_site } %>
      <% end %>
      <% end %>
      <%= f.label :new_a_web_site, '添加网站地址', :id => :new_a_web_site, :class => (customer.web_sites.any? ? 'hidden' : '') %>
      <script>
        $('#new_a_web_site').click(function(){
          $(this).hide();
          $('#new_web_site').show();
          $(this).before(replace_id($('#web_sites .item').size(),"<%= j customer_web_site_html_template(f) %>"));
        });
      </script>
      <div id="new_web_site" class='item <%= customer.web_sites.any? ? '' : 'hidden' %>'>
        <%= link_to_function "再添加一个","", :class => :new_item   %>
        <script>
          $('#new_web_site a').click(function() {
            $(this).before(replace_id($('#web_sites .item').size(),"<%= j customer_web_site_html_template(f) %>"));
          });
        </script>
      </div>
    </div>
  </div>
  <div class="grid_12 line">
    <div class="grid_2">地址</div>
    <div id="addresses" class="grid_9">
      <% customer.addresses.each do |address| %>
      <%= f.fields_for :addresses, address do |pf| %>
        <%= render :partial => 'address_in_form.html', :locals => { :pf => pf, :address => address } %>
      <% end %>
      <% end %>
      <%= f.label :new_a_address, '添加地址', :id => :new_a_address, :class => (customer.addresses.any? ? 'hidden' : '') %>
      <script>
        $('#new_a_address').click(function(){
          $(this).hide();
          $('#new_address').show();
          $(this).before(replace_id($('#addresses .item').size(),"<%= j customer_address_html_template(f) %>"));
        });
      </script>
      <div id="new_address" class='item <%= customer.addresses.any? ? '' : 'hidden' %>'>
        <%= link_to_function "再添加一个","", :class => :new_item   %>
        <script>
          $('#new_address a').click(function() {
            $(this).before(replace_id($('#addresses .item').size(),"<%= j customer_address_html_template(f) %>"));
          });
        </script>
      </div>
    </div>
  </div>
  <div class="bg_info grid_12 line">
    <div class="grid_11">
      背景信息<small>(比如: 个人简介,备注,你们如何认识的等等)</small>
    </div>
    <div class="grid_11">
      <%= f.text_area :background_info %>
    </div>
  </div>
  <div class="who_can_see grid_12 line">
    <div class="grid_11">
      还有谁能看到该联系人
    </div>
    <div class="grid_11 scope_type">
      <%= f.radio_button :visible_scope, 'everyone' %><%= f.label :visible_scope_everyone,'所有人' %>
    </div>
    <script type="text/javascript" charset="utf-8">
      $(document).everyTime(300,'visible_scope_timer',function() {        
         //console_debug('------------------------------------------');
        var value = $("input[@type=radio][name='customer[visible_scope]'][checked]").val();
        //$("input[name='customer[visible_scope]']").each(function() {
          //console_debug($(this).attr('id') + '  ' + $(this).attr('checked') + '   ~~~' + );
          //if($(this).attr('checked') == 'checked') {
        if(value == 'everyone') {
          $('.scope_type_items').hide();
        } else if(value == 'myself') {
          $('.scope_type_items').hide();
        } else if( value == 'groups') {
          $('#scope_type_groups_items').show();
          $('#scope_type_users_items').hide();
        } else if(value == 'users') {          
          $('#scope_type_groups_items').hide();
          $('#scope_type_users_items').show();
        } 
          //}
//        });
      });       
    </script>
    <div class="grid_11 scope_type">
      <%= f.radio_button :visible_scope, 'myself' %><%= f.label :visible_scope_myself,'仅仅我自己' %>
    </div>
    <div class="grid_11 scope_type">
      <%= f.radio_button :visible_scope,'groups' %><%= f.label :visible_scope_groups,'选择一些分组' %>
    </div>
    <div id='scope_type_groups_items' class="grid_11 scope_type_items <%= customer.visible_scope.groups? ? '' : 'hidden' %>">
      <% customer.customer_visible_to_groups.each do |customer_visible_to_group| %>       
      <%= render :partial => 'group_in_form.html', :locals => { :f => f, :customer_visible_to_group => customer_visible_to_group } %>
      <% end %>
      <div class='item grid_8'>
        <select id='add_group'>          
        </select>
      </div>
    </div>
    <script type="text/javascript" charset="utf-8">
      function init_add_group_select() {
        $('#add_group').html("<option value='-1'>请选择要添加的分组</option>"); 
        <% current_user.enterprise.groups.each do |group| %>
        if($('#group_<%= group.id %>').length == 0 || $('#group_<%= group.id %> .destory').val() == 'true' ) {
          $('#add_group').append("<option value='<%= group.id %>'><%= group.name %></option>"); 
        }
        <% end %>
      }
      $(document).ready(function() {
        init_add_group_select();
      });      
      $('#add_group').change(function() {
        <% current_user.enterprise.groups.each do |group| %>
        if($(this).val() == <%= group.id %>) {
          if($('#group_<%= group.id %>').length == 0 ) {
            $('#add_group').parent().before("<%= j render(:partial => 'group_in_form.html', :locals => { :f => f, :customer_visible_to_group => CustomerVisibleToGroup.new(:group_id => group.id) }) %>");
          } else  {
            $('#group_<%= group.id %>').show();
            $('#group_<%= group.id %> .destory').val('false');
          }
        }        
        <% end %>
        init_add_group_select();
      });
    </script>
    <div class="grid_11 scope_type">
      <%= f.radio_button :visible_scope,'users' %><%= f.label :visible_scope_users,'选择一些同事' %>
    </div>
    <div id='scope_type_users_items' class="grid_11 scope_type_items <%= customer.visible_scope.users? ? '' : 'hidden' %>">
      <% customer.customer_visible_to_users.each do |customer_visible_to_user| %>
      <%= render :partial => 'user_in_form.html', :locals => { :f => f, :customer_visible_to_user => customer_visible_to_user } %>
      <% end %>
      <div class='item grid_8'>
        <select id='add_user'>          
        </select>
      </div>
    </div>
  </div>
  <script type="text/javascript" charset="utf-8">
    function init_add_user_select() {
      $('#add_user').html("<option value='-1'>请选择要添加的同事</option>"); 
      <% current_user.enterprise.users.each do |user| %>
      if($('#user_<%= user.id %>').length == 0 || $('#user_<%= user.id %> .destory').val() == 'true' ) {
        $('#add_user').append("<option value='<%= user.id %>'><%= user.full_name %></option>"); 
      }
      <% end %>
    }
    $(document).ready(function() {
      init_add_user_select();
    });      
    $('#add_user').change(function() {
      <% current_user.enterprise.users.each do |user| %>
      if($(this).val() == <%= user.id %>) {
        if($('#user_<%= user.id %>').length == 0 ) {
          $('#add_user').parent().before("<%= j render(:partial => 'user_in_form.html', :locals => { :f => f, :customer_visible_to_user => CustomerVisibleToUser.new(:user_id => user.id) }) %>");
        } else  {
          $('#user_<%= user.id %>').show();
          $('#user_<%= user.id %> .destory').val('false');
        }
      }        
      <% end %>
      init_add_user_select();
    });
  </script>
  <div class="grid_12 bottom">
    <div class="grid_10">
      <%= f.submit "保存该联系人资料"%><small>或</small><%= link_to "离开", customers_url   %>
    </div>
  </div>